<template>
	<view class="container">
		<uni-list>
			<uni-list-item v-for="item,index in list" :key="index" :title="item.name" :note="item.title"
				clickable="true" :to="'../chat/chat?id='+item.id" thumbSize="lg" :rightText="item.date"
				:clickable="true" :showArrow="true">
				<template v-slot:header>
					<view class="round">
						<image :src="item.icon" mode="aspectFill"></image>
					</view>
				</template>
				<template v-slot:footer>
					<uni-badge :text="item.unread" type="error" v-if="item.unread"></uni-badge>
				</template>
			</uni-list-item>
		</uni-list>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: {
					"id": '',
					"title": '',
					"content": '',
					"date": '',
					"name": ''
				}
			}
		},
		onLoad() {
			uni.showLoading({
				title: '加载中',
				mask: false
			});
			uni.request({
				url: 'http://localhost:8090/freshmenapp/message/list',
				method: 'POST',
				data: {},
				success: res => {
					console.log(res);
					this.list = res.data.list;
					uni.showToast({
						title: '成功'
					});
					setTimeout(() => {
						uni.hideLoading()
					}, 2000)
				},
				fail: () => {
					uni.showToast({
						title: '失败',
						icon: 'none'
					});
				},
				complete: () => {}
			});
		}
	}
</script>

<style>
	.round {
		width: 80rpx;
		height: 80rpx;
		border-radius: 50%;
		overflow: hidden;
		margin-right: 15rpx;
	}

	.round image {
		width: 100%;
		height: 100%;
	}
</style>